/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */

var insertionSortList = function (head) {
    let dummy = new ListNode(0)
    dummy.next = head
    let pre = dummy
    let cur = head
    while (cur) {
        let next = cur.next
        if (next && next.val < cur.val) {
            while (pre.next.val < next.val) {
                pre = pre.next
            }
            cur.next = next.next
            next.next = pre.next
            pre.next = next
            pre = dummy
        } else {
            cur = next
        }
    }
    return dummy.next
};